﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;


/**
 * 需要asset store下载 DOTween 插件
 * 
 * Rigidbody2D 组件需要将 Collision Detection 设为 Continuous，将 Constraints/Freeze Rotation Z 勾选
 */
public partial class PlayerController : MonoBehaviour
{

    [SerializeField]
    public PlayerData playerData;


    // == 移动 ==
    // 奔跑速度倍率
    private float runSpeedRate = 60f;
    // 由 Mathf.SmoothDamp 计算出的x轴速度
    private float currentVelocityX;

    private bool isMoving;
    private bool isFaceToRight = true;     // 是否面向右方

    // == 跳跃 ==
    private bool isJumping;
    private bool isFalling;
    private bool isHitting;

    // == 冲刺 == 
    private bool wasDashed;     // 是否已冲刺过

    // == 地面判定 ==
    private bool isOnGround;

    
    // == 其他 ==
    private Rigidbody2D rb;
    private Animator anim;
    private SpriteRenderer sr;

    
    void Awake()
    {
        rb = GetComponent<Rigidbody2D>();
        anim = GetComponent<Animator>();
        sr = GetComponent<SpriteRenderer>();
    }


    void FixedUpdate()
    {
        Movement();
        SwitchAnimation();
    }


    // 显示判定框
    private void OnDrawGizmos()
    {
        Gizmos.color = Color.red;
        Gizmos.DrawWireCube((Vector2)transform.position + playerData.centerPointOffset, playerData.overlapBoxSize);
    }
}
